package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Softwares;
import com.ruoyi.web.service.ISoftwaresService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 软件Controller
 * 
 * @author song
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/software/softwares")
public class SoftwareController extends BaseController
{
    @Autowired
    private ISoftwaresService softwaresService;

    /**
     * 查询软件列表
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:list')")
    @GetMapping("/list")
    public TableDataInfo list(Softwares softwares)
    {
        startPage();
        softwares.setAliasName(softwares.getSoftwareName());
        List<Softwares> list = softwaresService.selectSoftwaresList(softwares);
        return getDataTable(list);
    }

    /**
     * 导出软件列表
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:export')")
    @Log(title = "软件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Softwares softwares)
    {
        List<Softwares> list = softwaresService.selectSoftwaresList(softwares);
        ExcelUtil<Softwares> util = new ExcelUtil<Softwares>(Softwares.class);
        util.exportExcel(response, list, "软件数据");
    }

    /**
     * 获取软件详细信息
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:query')")
    @GetMapping(value = "/{softwareId}")
    public AjaxResult getInfo(@PathVariable("softwareId") Long softwareId)
    {
        return success(softwaresService.selectSoftwaresBySoftwareId(softwareId));
    }

    /**
     * 新增软件
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:add')")
    @Log(title = "软件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Softwares softwares)
    {
        return toAjax(softwaresService.insertSoftwares(softwares));
    }

    /**
     * 修改软件
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:edit')")
    @Log(title = "软件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Softwares softwares)
    {
        return toAjax(softwaresService.updateSoftwares(softwares));
    }

    /**
     * 删除软件
     */
    @PreAuthorize("@ss.hasPermi('software:softwares:remove')")
    @Log(title = "软件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{softwareIds}")
    public AjaxResult remove(@PathVariable Long[] softwareIds)
    {
        return toAjax(softwaresService.deleteSoftwaresBySoftwareIds(softwareIds));
    }
}
